{% extends "base.html" %}

{% block title %}Editing File{% endblock %}

{% block scripts %}
	{{ parent() }}
	<script type="text/javascript" src="{{ settings.assets_url }}javascript/jquery.redirect.min.js"></script>
{% endblock %}

{% block servername %}
<ul class="nav navbar-nav">
	<li class="active dynUpdate" id="{{ server.id }}"><a><i id="applyUpdate" class="fa fa-circle-o-notch fa-spinner fa-spin"></i> {{ server.name }}</a></li>
</ul>
{% endblock %}

{% block sidebar %}
<div class="list-group">
	<a href="#" class="list-group-item list-group-item-heading"><strong>{{ lang.sidebar_acc_actions }}</strong></a>
	<a href="../../account.php" class="list-group-item">{{ lang.sidebar_settings }}</a>
	<a href="../../totp.php" class="list-group-item">TOTP {{ lang.sidebar_settings }}</a>
	<a href="../../servers.php" class="list-group-item">{{ lang.sidebar_servers }}</a>
</div>
<div class="list-group">
	<a href="#" class="list-group-item list-group-item-heading"><strong>{{ lang.sidebar_server_acc }}</strong></a>
	<a href="../index.php" class="list-group-item">{{ lang.sidebar_overview }}</a>
	<a href="index.php" class="list-group-item active">{{ lang.sidebar_files }}</a>
	{% if permission.users.view == true %}<a href="../users/list.php" class="list-group-item">Manage Subusers</a>{% endif %}
	<a href="../settings.php" class="list-group-item">{{ lang.sidebar_manage }}</a>
	<a href="../plugins/index.php" class="list-group-item">{{ lang.sidebar_plugins }}</a>
</div>
{% endblock %}

{% block content %}
<div class="col-9" id="load_files">
	<span id="save_status" style="display:none;width: 100%;"></span>
	{% if error %}
		{{ error|raw }}
	{% else %}
	<form method="post" id="editing_file">
		<div class="form-group">
			<div>
				<textarea name="file_contents" id="live_console" style="border: 1px solid #dddddd;height:500px;" class="form-control console">{{ contents }}</textarea>
			</div>
		</div>
		{% if permission.files.save == true %}
			<div class="form-group">
				<div>
					<input type="hidden" name="file" value="{{ file }}" />
					{{ xsrf|raw }}
					<button class="btn btn-primary btn-sm" id="save_file">{{ lang.string_save }}</button>
					<button class="btn btn-default btn-sm" onclick="window.location='index.php?dir={{ directory|url_encode }}';return false;">{{ lang.node_files_edit_back }}</button>
				</div>
			</div>
		{% endif %}
    </form>
    {% endif %}
</div>
<script type="text/javascript">
$(window).load(function(){$("#save_file").click(function(a){a.preventDefault();var e=$("input[name='file']").val(),s=$("#live_console").val(),l=$("input[name='xsrf']").val();$("#save_file").append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass("disabled"),$.ajax({type:"POST",url:"../ajax/files/save.php",data:{file:e,file_contents:s,xsrf:l},success:function(a){$("#save_status").html(a),$("#save_file").html("Save").removeClass("disabled"),$("#save_status").slideDown()}})})});</script>
{% endblock %}
